<?php


namespace App\Http\Controllers;


class ResultJsonController extends Controller
{
    public $message = 'success';
    public $code = 0;
    public $data = array();

    public function setData($data)
    {
        if(!empty($data))
        {
            $this->data = $data;
        }
        return $this;
    }
    public function setMessage($message)
    {
        if(!empty($message))
        {
            $this->message = $message;
        }
        return $this;
    }
    public function setCode($code)
    {
        if(!empty($code))
        {
            $this->code = $code;
        }
        return $this;
    }
    public function errorJson()
    {
       die(json_encode(
           array(
               'code' => $this->code,
               'message' => $this->message,
               'data' => $this->data
           ),true));
    }

    public function errorArray()
    {
        return array(
            'code' => $this->code,
            'message' => $this->message,
            'data' => $this->data
        );
    }
}